package com.woniuedu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuedu.dto.CommentDto;
import com.woniuedu.dto.CourseInfoDto;
import com.woniuedu.dto.CourseVideo;
import com.woniuedu.dto.FindCourseDto;
import com.woniuedu.entity.Comment;
import com.woniuedu.entity.Course;
import com.woniuedu.entity.ResponseEntity;
import com.woniuedu.service.ICourseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * author: 承雍
 * Date: 2022/4/19 10:47
 * Description:课程控制层
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired(required = false)
    private ICourseService courseService;

    @PostMapping({"/findAllCourse/{currentPage}/{pageSize}", "/findAllCourse"})
    @ApiOperation(value = "查看全部的课程信息")
    public IPage<Course> findAllCourse(@PathVariable(required = false) Integer currentPage,
                                       @PathVariable(required = false) Integer pageSize,
                                       @RequestBody FindCourseDto findCourseDto) {
        return courseService.findAllCourse(currentPage, pageSize,findCourseDto);
    }

    @GetMapping("/findCourseInfo/{id}")
    @ApiOperation(value = "根据id查询课程详细信息")
    public ResponseEntity<CourseInfoDto> findCourseInfo(@PathVariable String id){
        return courseService.findCourseInfo(id);
    }

    @GetMapping("/findCourseVideo/{id}")
    @ApiOperation(value = "查询视频资源")
    public List<CourseVideo> findCourseVideo(@PathVariable String id){
        return courseService.findCourseVideo(id);
    }

    @PostMapping("/findAllComment")
    @ApiOperation(value = "查询课程的评论")
    public IPage<Comment> findAllComment(@RequestBody CommentDto commentDto){
        return courseService.findAllComment(commentDto);
    }
}
